use pumpkin_data::packet::clientbound::PLAY_LOGIN;
use pumpkin_util::{math::position::BlockPos, resource_location::ResourceLocation};

use pumpkin_macros::packet;
use serde::Serialize;

use crate::VarInt;

#[derive(Serialize)]
#[packet(PLAY_LOGIN)]
pub struct CLogin<'a> {
    pub entity_id: i32,
    pub is_hardcore: bool,
    pub dimension_names: &'a [ResourceLocation],
    pub max_players: VarInt,
    pub view_distance: VarInt,
    pub simulated_distance: VarInt,
    pub reduced_debug_info: bool,
    pub enabled_respawn_screen: bool,
    pub limited_crafting: bool,
    // Spawn info
    pub dimension_type: VarInt,
    pub dimension_name: ResourceLocation,
    /// First 8 bytes of the SHA-256 hash of the world's seed. Used client side for biome noise
    pub hashed_seed: i64,
    pub game_mode: u8,
    pub previous_gamemode: i8,
    pub debug: bool,
    pub is_flat: bool,
    pub death_dimension_name: Option<(ResourceLocation, BlockPos)>,
    pub portal_cooldown: VarInt,
    pub sealevel: VarInt,
    pub enforce_secure_chat: bool,
}

impl<'a> CLogin<'a> {
    #[expect(clippy::too_many_arguments)]
    pub fn new(
        entity_id: i32,
        is_hardcore: bool,
        dimension_names: &'a [ResourceLocation],
        max_players: VarInt,
        view_distance: VarInt,
        simulated_distance: VarInt,
        reduced_debug_info: bool,
        enabled_respawn_screen: bool,
        limited_crafting: bool,
        dimension_type: VarInt,
        dimension_name: ResourceLocation,
        hashed_seed: i64,
        game_mode: u8,
        previous_gamemode: i8,
        debug: bool,
        is_flat: bool,
        death_dimension_name: Option<(ResourceLocation, BlockPos)>,
        portal_cooldown: VarInt,
        sealevel: VarInt,
        enforce_secure_chat: bool,
    ) -> Self {
        Self {
            entity_id,
            is_hardcore,
            dimension_names,
            max_players,
            view_distance,
            simulated_distance,
            reduced_debug_info,
            enabled_respawn_screen,
            limited_crafting,
            dimension_type,
            dimension_name,
            hashed_seed,
            game_mode,
            previous_gamemode,
            debug,
            is_flat,
            death_dimension_name,
            portal_cooldown,
            sealevel,
            enforce_secure_chat,
        }
    }
}
